package com.itheima.dao;

import com.itheima.pojo.Setmeal;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface SetmealDao_scg {
//    @Insert("insert into t_setmeal (name,code,helpCode,sex,age,price,remark,attention,img) values(#{name},#{code},#{helpCode},#{sex},#{age},#{price},#{remark},#{attention},#{img})")
//    @Options(useGeneratedKeys = true)
//    void add(Setmeal setmeal);
//
//    @Insert("insert into t_setmeal_checkgroup (setmeal_id,checkgroup_id) values (#{setmeal_id},#{checkgroup_id})")
//    void setSetmealAndCheckGroup(Map<String, Integer> map);
//
//    @Select("select * from t_setmeal where code = #{code} or name = #{name} or helpCode = #{helpCode}")
//    Page<CheckItem> selectByCondition(String queryString);
//
//    @Select("select * from t_setmeal")
//    Page<CheckItem> findAll();
//
//    @Select("select * from t_setmeal")
//    List<Setmeal> findAllByMobile();

    @Select("select * from t_setmeal where id=#{id}")
    @Results({
            @Result(id = true,property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "code", column = "code"),
            @Result(property = "helpCode", column = "helpCode"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "age", column = "age"),
            @Result(property = "price", column = "price"),
            @Result(property = "remark", column = "remark"),
            @Result(property = "attention", column = "attention"),
            @Result(property = "img", column = "img"),
            @Result(property = "checkGroups", column = "id",
                    javaType = List.class,
                    many = @Many(select = "com.itheima.dao.CheckGroupDao.findCheckGroupById")

            ),
    })
    Setmeal findById(int id);

//    @Select("select s.name,count(o.id) as value from t_order o ,t_setmeal s where o.setmeal_id = s.id group by s.name")
//    List<Map<String, Object>> findSetmealCount();

    @Select("select * from t_setmeal")
    List<Setmeal> find();

    @Select("SELECT id FROM t_setmeal WHERE id = (SELECT setmeal_id FROM t_order WHERE id = #{id})")
    List<Integer> findByOrderId(int id);
}
